var r2 = function(selector){
	return new r2.prototype.init(selector);
};

r2.prototype = {
	version:"alpha 20110104",
	length:0,
	init:function(selector){
		if(typeof selector === "function"){
			window.onload = selector;
			this[0] = document;
			this.length = 1;
		} else if(selector){
			if (/^\w+$/.test(selector)){ // element name
				selector = document.getElementsByTagName(selector);
				return r2.merge(this, selector);
			} else { // #id
				var id = selector.substr(1);
				var elem = document.getElementById(id);
				if(elem){
					this[0] = elem;this.length = 1;
				}
			}
		}
		return this;
	}
};

r2.each = function(object, callback){
	for(var i = 0, length = object.length, value = object[0]; i < length; value = object[++i]){
		callback.call(value, i, value);
	}
	return object;
};

r2.merge = function(first,second){
	var i = first.length,j=0;
	while(second[j]!=undefined){
		first[i++]=second[j++];
	}
	first.length = i;
	return first;
}

r2.prototype.init.prototype = r2.fn = r2.prototype;
$ = r2;